<%--
  Created by IntelliJ IDEA.
  User: Lanan
  Date: 2017/12/28 0028
  Time: 9:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>微信公众号专属二维码</title>
</head>
<body>

<script type="text/javascript">

    var wechatPublicQrCodeDataGrid;
    $(function () {
        wechatPublicQrCodeDataGrid = $("#wechatPublicQrCodeDataGrid").datagrid({
            url:"${path}/wechat/public/number/exclusive/qrCode/list.do",
            fit:true,
            idField:'id',
            rownumbers:true,
            pagination:true,
            fitColumns:true,
            singleSelect:true,
            frozenColumns : [[{
                title : 'ID',
                field : 'id',
                align : 'center',
                checkbox:true
            }]],
            columns : [[{
                title : '二维码标题',
                field : 'name',
                align : 'center'
            }, {
                title : '二维码key',
                field : 'k',
                align : 'center',
            }, {
                field : 'action',
                align : 'center',
                title : '操作',
                width : '300px',
                formatter : function(value, row, index) {
                    var str = '';
                    <shiro:hasPermission name="/wechat/public/number/exclusive/qrCode/update.do">
                    str += $.formatString('<a href="javascript:void(0)" class="resource-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="updateExclusuveOrCode(\'{0}\');" >编辑</a>', index);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/wechat/public/number/exclusive/qrCode/delete.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="resource-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteExclusuveOrCode(\'{0}\');" >删除</a>', index);
                    </shiro:hasPermission>
                    <shiro:hasPermission name="/wechat/public/number/exclusive/qrCode/create.do">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="resource-easyui-linkbutton-submit" data-options="plain:true,iconCls:\'fi-refresh icon-blue\'" onclick="createExclusuveOrCode(\'{0}\');" >生成二维码</a>', index);
                    </shiro:hasPermission>
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.resource-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.resource-easyui-linkbutton-del').linkbutton({text:'删除'});
                $('.resource-easyui-linkbutton-submit').linkbutton({text:'生成二维码'});
            },
            toolbar : '#wechatPublicQrCodeDataGridToolbar'
        })
    })

    function insertExclusuveOrCode() {
        flag = 'add';
        $("#qr_code_form").form("clear");
        $("#qr_code_dialog").dialog({title: "添加微信公众号专属二维码"});
        $("#qr_code_dialog").dialog("open");
    }

    function updateExclusuveOrCode(index) {

        wechatPublicQrCodeDataGrid.datagrid('selectRow',index);  //选中
        var row = wechatPublicQrCodeDataGrid.datagrid('getSelected');      //获取选中行

        if (row == null) {
            $.messager.alert("提示","请选择要修改的消息模板！","info");
            return;
        }
        flag = 'update';
        $("#qr_code_form").form("load", row);
        $("#qr_code_dialog").dialog({title: "修改微信公众号模板消息"});
        $("#qr_code_dialog").dialog("open");
    }

    function submitExclusuveOrCode() {
        var url = "";
        var msg = "";
        if (flag == 'add') {
            msg = "添加";
            url = "${path}/wechat/public/number/exclusive/qrCode/insert.do"
        } else {
            msg = "修改";
            url = "${path}/wechat/public/number/exclusive/qrCode/update.do"
        }

        lananUpdateOrInsert(msg, url, "qr_code_form", "qr_code_dialog", "wechatPublicQrCodeDataGrid")
    }

    function deleteExclusuveOrCode(index) {
        wechatPublicQrCodeDataGrid.datagrid('selectRow',index);  //选中
        lananDelete("wechatPublicQrCodeDataGrid", "您确定要删除该二维码信息", "${path}/wechat/public/number/exclusive/qrCode/delete.do")
    }

    function createExclusuveOrCode(index) {
        wechatPublicQrCodeDataGrid.datagrid('selectRow',index);  //选中
        var row = wechatPublicQrCodeDataGrid.datagrid('getSelected');      //获取选中行
        $.messager.confirm("确认","您确定要生成该专属二维码?", function(yes){
            if(yes){
                $.messager.progress();
                $.ajax({
                    url:"${path}/wechat/public/number/exclusive/qrCode/create.do",
                    type:"post",
                    data:{id : row.id},
                    dataType:"json",
                    success:function(data){
                        $.messager.progress("close");
                        if(data.success){
                            $.messager.show({
                                title:"生成成功",
                                msg:"生成成功!",
                                timeout:600,
                                style:"left:30%;top:10%",
                                showType:"fade"
                            });
                            $("#" + lableId).treegrid('clearSelections');
                            $("#" + lableId).treegrid("reload");
                        }else{
                            $.messager.alert("生成失败", data.msg,"error");
                        }
                    },
                    error:function(){
                        $.messager.progress("close");
                        $.messager.alert("生成成功", "服务器连接失败!","error");
                    }
                });
            }
        });
    }

</script>

<!-- 数据表格 begin -->
<table id="wechatPublicQrCodeDataGrid"></table>

<div id="wechatPublicQrCodeDataGridToolbar" style="display: none;">
    <shiro:hasPermission name="/wechat/public/number/exclusive/qrCode/insert.do">
        <a onclick="insertExclusuveOrCode()" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'l-btn-icon fi-plus icon-green'">添加</a>
    </shiro:hasPermission>
</div>

<div class="easyui-dialog" id="qr_code_dialog" data-options="closed:true,modal:true,width:400,height:200">
    <form id="qr_code_form" method="post">
        <table align="center" width="100%" style="margin-top: 20px" cellpadding="4">
            <input hidden="hidden" name="id"/>
            <tr>
                <td width="35%" align="right"><label>二维码标题:</label></td>
                <td width="65%" align="left"><input name="name" class="easyui-validatebox" data-options="required:true,missingMessage:'请输入模板ID'"/></td>
            </tr>
            <tr>
                <td align="right"><label>二维码key:</label></td>
                <td align="left"><input name="k" class="easyui-validatebox" data-options="required:true,missingMessage:'请输入模板标题'"/></td>
            </tr>
        </table>

        <div style="margin-top: 30px;text-align: center">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'", onclick="submitExclusuveOrCode()">提交</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'", onclick="$('#qr_code_dialog').dialog('close')">取消</a>
        </div>
    </form>
</div>

</body>
</html>
